<!DOCTYPE html>
<html lang="en">
<head>
  <base href="/">
  <meta charset="UTF-8">
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
  <link rel="stylesheet" href="x-admin/css/font.css">
  <link rel="stylesheet" href="x-admin/css/xadmin.css">
  <script type="text/javascript" src="x-admin/js/jquery.min.js"></script>
  <script src="x-admin/lib/layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript" src="x-admin/js/xadmin.js"></script>
  <!--[if lt IE 9]>
  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
  <![endif]-->
</head>
<body>
<div style="width: 90%;margin: 0 30px 0 auto">
  <form id="edit" lay-filter="edit" class="layui-form">
    <input type="hidden" name="id" id="id" value="<%= brand.id %>">
    <div class="layui-form-item">
      <label class="layui-form-label" for="name"><span class="x-red">*</span>品牌名称</label>
      <div class="layui-input-block">
        <input type="text" name="brand_name" id="brand_name" placeholder="请输入品牌名称" autocomplete="off"
               value="<%= brand.brand_name %>" lay-verify="required" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" for="profile">介绍</label>
      <div class="layui-input-block">
        <textarea placeholder="请输入内容" id="profile" name="profile"
                  class="layui-textarea"><%= brand.profile %></textarea>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" for="status">状态</label>
      <div class="layui-input-block">
        <select name="status" id="status">
          <option value="1">可用</option>
          <option value="2">禁用</option>
        </select>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label"></label>
      <div class="layui-input-block">
        <button class="layui-btn" type="submit" lay-submit lay-filter="submitBtn">提交</button>
      </div>
    </div>
  </form>
</div>
</body>
<script>

  layui.use(["form"], function () {
    const form = layui.form;
    /*获取状态值*/
    let status = "<%= brand.status %>";
    /*状态值存在则表示修改*/
    if (status) {
      $("#status").val(status);
      /*在layui中通过js更新select的值后，必须调用form.render去重新渲染*/
      form.render();
    }

    form.on("submit(submitBtn)", function ({field}) {
      $.ajax({
        url: "brand/update",
        data: field,
        method: "post",
        dataType: "json",
        success(res) {
          if (res.code === 200) {
            layer.msg((field.id ? "修改" : "添加") + "成功", {icon: 6}, function () {
              const index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
              parent.layer.close(index); //再执行关闭
              parent.table.reload("dataList")
            });
          } else {
            layer.alert(res.msg, {icon: 5});
          }
        }
      });
      return false;
    });
  });
</script>
</html>
